package com.notice.resulthandler;

import android.app.Activity;
import android.content.Intent;
import android.view.View;

import com.google.zxing.Result;
import com.google.zxing.client.result.ParsedResult;
import com.google.zxing.client.result.ProductParsedResult;
import com.notice.qrcode.R;
import com.notice.qrcode.WebViewActivity;

/**
 * Handles generic products which are not books.
 * 
 */
public final class ProductResultHandler extends ResultHandler {

	public ProductResultHandler(final Activity activity, ParsedResult result,
			Result rawResult) {
		super(activity, result, rawResult);

		showButton(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				ProductParsedResult productResult = (ProductParsedResult) getResult();
				Intent intent = new Intent(activity, WebViewActivity.class);
				switch (v.getId()) {
				case R.id.bt_dangdang:
					intent.putExtra("type", "dang");
					intent.putExtra("value", productResult.getProductID());
					launchIntent(intent);
					break;
				case R.id.bt_taobao:
					intent.putExtra("type", "taobao");
					intent.putExtra("value", productResult.getProductID());
					launchIntent(intent);
					break;
				case R.id.bt_yitao:
					intent.putExtra("type", "yitao");
					intent.putExtra("value", productResult.getProductID());
					launchIntent(intent);
					break;
				}
			}
		});

	}

	@Override
	public int getDisplayTitle() {
		return R.string.result_product;
	}
}
